package com.acdc.device.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.acdc.device.mapper.MeterDeviceMapper;
import com.acdc.device.domain.MeterDevice;
import com.acdc.device.service.IMeterDeviceService;

/**
 * 电能表管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-19
 */
@Service
public class MeterDeviceServiceImpl implements IMeterDeviceService 
{
    @Autowired
    private MeterDeviceMapper meterDeviceMapper;

    /**
     * 查询电能表管理
     * 
     * @param id 电能表管理主键
     * @return 电能表管理
     */
    @Override
    public MeterDevice selectMeterDeviceById(Long id)
    {
        return meterDeviceMapper.selectMeterDeviceById(id);
    }

    /**
     * 查询电能表管理列表
     * 
     * @param meterDevice 电能表管理
     * @return 电能表管理
     */
    @Override
    public List<MeterDevice> selectMeterDeviceList(MeterDevice meterDevice)
    {
        return meterDeviceMapper.selectMeterDeviceList(meterDevice);
    }

    /**
     * 新增电能表管理
     * 
     * @param meterDevice 电能表管理
     * @return 结果
     */
    @Override
    public int insertMeterDevice(MeterDevice meterDevice)
    {
        meterDevice.setCreateTime(DateUtils.getNowDate());
        return meterDeviceMapper.insertMeterDevice(meterDevice);
    }

    /**
     * 修改电能表管理
     * 
     * @param meterDevice 电能表管理
     * @return 结果
     */
    @Override
    public int updateMeterDevice(MeterDevice meterDevice)
    {
        meterDevice.setUpdateTime(DateUtils.getNowDate());
        return meterDeviceMapper.updateMeterDevice(meterDevice);
    }

    /**
     * 批量删除电能表管理
     * 
     * @param ids 需要删除的电能表管理主键
     * @return 结果
     */
    @Override
    public int deleteMeterDeviceByIds(Long[] ids)
    {
        return meterDeviceMapper.deleteMeterDeviceByIds(ids);
    }

    /**
     * 删除电能表管理信息
     * 
     * @param id 电能表管理主键
     * @return 结果
     */
    @Override
    public int deleteMeterDeviceById(Long id)
    {
        return meterDeviceMapper.deleteMeterDeviceById(id);
    }

    @Override
    public MeterDevice selectMeterDeviceByServerAddress(String serverAddress)
    {
        return meterDeviceMapper.selectMeterDeviceByServerAddress(serverAddress);
    }

    @Override
    public List<MeterDevice> selectMeterDeviceByIotModuleId(Long iotModuleId)
    {
        return meterDeviceMapper.selectMeterDeviceByIotModuleId(iotModuleId);
    }

    @Override
    public int resetIotModule(Long meterDeviceId)
    {
        MeterDevice meterDevice = meterDeviceMapper.selectMeterDeviceById(meterDeviceId);
        if (meterDevice == null) {
            throw new RuntimeException("电能表管理不存在");
        }
        return meterDeviceMapper.resetIotModule(meterDeviceId);
    }
}
